interface ConfirmOptions {
  title?: string
  content: string
  confirmText?: string
  confirmColor?: string
  showCancel?: boolean
  cancelText?: string
  confirm: () => void
  cancel?: () => void
}

export function useModal() {
  function confirm(options: ConfirmOptions) {
    uni.showModal({
      title: options.title || '提示',
      content: options.content,
      confirmText: options.confirmText || '确定',
      confirmColor: options.confirmColor || '#ff0000',
      showCancel: (options.showCancel === void 0) ? true : options.showCancel,
      cancelText: options.cancelText || '关闭',
      success(res) {
        if (res.confirm) {
          options.confirm && options.confirm()
        } else if (res.cancel) {
          options.cancel && options.cancel()
        }
      },
    })
  }

  return {
    confirm,
  }
}
